﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rose;

namespace ZMO_Editor
{
    public struct Quaternion
    {
	   public float m_X;
	   public float m_Y;
	   public float m_Z;
	   public float m_S;
    }

    public struct Vector3
    {
	    public float m_X;
	    public float m_Y;
	    public float m_Z;
    }

    public struct Vector2
    {
	    public float m_X;
	    public float m_Y;
    }

    public enum Channel_Type
    {
        POSITION = 0x2,
        ROTATION = 0x4,
        NORMAL = 0x8,
        ALPHA = 0x10,
        UV1 = 0x20,
        UV2 = 0x40,
        UV3 = 0x80,
        UV4 = 0x100,
        TEXTUREANIM = 0x200,
        SCALE = 0x400
    };

    class Channel
    {
        public int m_Type;
        public int m_TrackId;
        public object m_Data;
    }

    class ZMO
    {
        public void Load(string a_FilePath)
        {
            m_File = new FileHandler();
            m_File.LoadFile(a_FilePath);
            m_FormatCode = m_File.ReadFSTR(8);
            m_FPS = m_File.ReadInt();
            m_FrameCount = m_File.ReadInt();
            m_ChannelCount = m_File.ReadInt();

            for (int i = 0; i < m_ChannelCount; i++)
            {
                Channel NewChannel = new Channel();
                NewChannel.m_Type = m_File.ReadInt();
                NewChannel.m_TrackId = m_File.ReadInt();

                #region ChannelType
                Channel_Type chan = (Channel_Type)NewChannel.m_TrackId;
                switch ((Channel_Type)NewChannel.m_Type)
                {
                    case Channel_Type.POSITION:
                        {
                            NewChannel.m_Data = new Vector3[m_FrameCount];

                        }
                        break;
                    case Channel_Type.ROTATION:
                        {
                            NewChannel.m_Data = new Quaternion[m_FrameCount];
                            bool check = true;

                        }
                        break;
                    case Channel_Type.NORMAL:
                        {
                            NewChannel.m_Data = new Vector3[m_FrameCount];
                        }
                        break;
                    case Channel_Type.ALPHA:
                        {
                            NewChannel.m_Data = new float[m_FrameCount];
                        }
                        break;
                    case Channel_Type.UV1:
                        {
                            NewChannel.m_Data = new Vector2[m_FrameCount];
                        }
                        break;
                    case Channel_Type.UV2:
                        {
                            NewChannel.m_Data = new Vector2[m_FrameCount];
                        }
                        break;
                    case Channel_Type.UV3:
                        {
                            NewChannel.m_Data = new Vector2[m_FrameCount];
                        }
                        break;
                    case Channel_Type.UV4:
                        {
                            NewChannel.m_Data = new Vector2[m_FrameCount];
                        }
                        break;
                    case Channel_Type.TEXTUREANIM:
                        {
                            NewChannel.m_Data = new float[m_FrameCount];
                        }
                        break;
                    case Channel_Type.SCALE:
                        {
                            NewChannel.m_Data = new float[m_FrameCount];
                        }
                        break;
                    default:
                        {
                            bool check = false;
                        }
                        break;
                }
                #endregion

                m_Channels.AddFirst(NewChannel);
            }                      
            

            //IEnumerator<Channel> It = new IEnumerator<Channel>( )

            #region Data
            for (int i = 0; i < m_FrameCount; i++)
            {
                foreach ( Channel channel in m_Channels )
                {
                    switch ((Channel_Type)channel.m_Type)
                    {
                        case Channel_Type.POSITION:
                            {
                                //channel.m_Data = new Vector3();
                                //Vector3[m_FrameCount] pos = new Vector3();
                                //Vector3 pos = (Vector3)channel.m_Data;
                                //Channel_Type.
                               // [i].m_X = m_File->ReadFloat();
                                //pos[i].m_Y = m_File->ReadFloat();
                                //pos[i].m_Z = m_File->ReadFloat();
                                //pos[i].m_X /= 100;
                                //pos[i].m_Y /= 100;
                                ///pos[i].m_Z /= 100;
                            }
                            break;
                        case Channel_Type.ROTATION:
                            {
                                Quaternion[] quad = ((Quaternion[])channel.m_Data);
                                quad[i].m_S = m_File.ReadFloat();

                                //quad[i].m_S = m_File->ReadFloat();
                                //quad[i].m_X = m_File->ReadFloat();
                                //quad[i].m_Y = m_File->ReadFloat();
                                //quad[i].m_Z = m_File->ReadFloat();
                            }
                            break;
                        case Channel_Type.NORMAL:
                            {
                                //Vector3* pos = (Vector3*)channel.m_Data;

                                //pos[i].m_X = m_File->ReadFloat();
                                //pos[i].m_Y = m_File->ReadFloat();
                                //pos[i].m_Z = m_File->ReadFloat();
                                //pos[i].m_X /= 100;
                                //pos[i].m_Y /= 100;
                                //pos[i].m_Z /= 100;
                            }
                            break;
                        case Channel_Type.ALPHA:
                            {
                                //float alpha = (float)channel.m_Data;

                                //alpha[i] = m_File->ReadFloat();
                            }
                            break;
                        case Channel_Type.UV1:
                            {
                                //Vector2* pos = (Vector2*)channel.m_Data;

                                //pos[i].m_X = m_File->ReadFloat();
                                //pos[i].m_Y = m_File->ReadFloat();
                                //pos[i].m_X /= 100;
                                //pos[i].m_Y /= 100;
                            }
                            break;
                        case Channel_Type.UV2:
                            {
                                //Vector2* pos = (Vector2*)channel.m_Data;

                                //pos[i].m_X = m_File->ReadFloat();
                                //pos[i].m_Y = m_File->ReadFloat();
                                //pos[i].m_X /= 100;
                                //pos[i].m_Y /= 100;
                            }
                            break;
                        case Channel_Type.UV3:
                            {
                                //Vector2* pos = (Vector2*)channel.m_Data;

                                //pos[i].m_X = m_File->ReadFloat();
                                //pos[i].m_Y = m_File->ReadFloat();
                                //pos[i].m_X /= 100;
                                //pos[i].m_Y /= 100;
                            }
                            break;
                        case Channel_Type.UV4:
                            {
                                //Vector2* pos = (Vector2*)channel.m_Data;

                                //pos[i].m_X = m_File->ReadFloat();
                                //pos[i].m_Y = m_File->ReadFloat();
                                //pos[i].m_X /= 100;
                                //pos[i].m_Y /= 100;
                            }
                            break;
                        case Channel_Type.TEXTUREANIM:
                            {
                                //float animation = (float)channel.m_Data;

                                //animation[i] = m_File->ReadFloat();
                            }
                            break;
                        case Channel_Type.SCALE:
                            {
                                //float* scale = (float*)channel.m_Data;

                                //scale[i] = m_File->ReadFloat();
                            }
                            break;
                    }
                }
 #endregion
                //m_Channels.
            }
        }
        public void Save(string a_FilePath)
        {

        }


        private FileHandler m_File;
        private string m_FormatCode;
        private int m_FPS;
        private int m_FrameCount;
        private int m_ChannelCount;
        LinkedList<Channel> m_Channels;      
    }
}
